/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package com.oop.example.gui;

import com.oop.example.processing.ExportTask;
import com.oop.example.processing.ProcessingFactory;
import com.oop.example.work.bel.Exporter;
import com.oop.example.utils.Utils;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Arrays;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author -
 */
public class ExportDialog extends javax.swing.JDialog {

    private ExportTask exportTask = new ProcessingFactory().getExportTask();

    public ExportDialog(Window parent) {
        super(parent, ModalityType.APPLICATION_MODAL);
        initComponents();
        String[] arr = {};
        String[] langs = Utils.getLangs().stringPropertyNames().toArray(arr);
        Arrays.sort(langs);
        jComboBoxContentLang.setModel(new DefaultComboBoxModel(langs));
        jComboBoxIndexLang.setModel(new DefaultComboBoxModel(langs));
        jTextFieldTarget.setText(new File("lingvo.xml").getAbsolutePath());
        jButtonExport.addActionListener(new DoActionListener());
        jButtonStop.addActionListener(new StopActionListener());
    }

    private class DoActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            exportTask.setFile(new File(jTextFieldTarget.getText()));
            exportTask.setIndexLanguage(jComboBoxIndexLang.getSelectedItem().toString());
            exportTask.setContentLanguage(jComboBoxContentLang.getSelectedItem().toString());
            exportTask.setNumeratorDictionary(jComboBoxNumerator.getSelectedItem().toString());
            exportTask.setSortingType("" + jComboBoxSorting.getSelectedIndex());
            exportTask.setDictionaryName(jTextFieldDictName.getText());
            exportTask.setTextIndicator(jTextPaneStatus);
            exportTask.setProgressIndicator(jProgressBar);
            exportTask.setExportLabels(jCheckBoxAddLabels.isSelected());
            exportTask.setFormatOutput(jCheckBoxFormat.isSelected());

            new Thread(exportTask).start();
        }
    }

    private class StopActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (exportTask != null) {
                exportTask.stop();
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelDictName = new javax.swing.JLabel();
        jTextFieldDictName = new javax.swing.JTextField();
        jCheckBoxAddLabels = new javax.swing.JCheckBox();
        jLabelIndexLang = new javax.swing.JLabel();
        jComboBoxIndexLang = new javax.swing.JComboBox();
        jLabelContentLang = new javax.swing.JLabel();
        jComboBoxContentLang = new javax.swing.JComboBox();
        jLabelNumerator = new javax.swing.JLabel();
        jComboBoxNumerator = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxSorting = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPaneStatus = new javax.swing.JTextPane();
        jButtonExport = new javax.swing.JButton();
        jCheckBoxFormat = new javax.swing.JCheckBox();
        jLabelTarget = new javax.swing.JLabel();
        jTextFieldTarget = new javax.swing.JTextField();
        jProgressBar = new javax.swing.JProgressBar();
        jButtonStop = new javax.swing.JButton();
        jCheckBoxMergeHomonym = new javax.swing.JCheckBox();
        jCheckBoxMergeHomograph = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabelDictName.setText("Имя словаря");

        jTextFieldDictName.setText("First version 1.0 Rus-Bel");

        jCheckBoxAddLabels.setSelected(true);
        jCheckBoxAddLabels.setText("Добавить словарь помет");

        jLabelIndexLang.setText("Язык словника");

        jComboBoxIndexLang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabelContentLang.setText("Язык тела статьи");

        jComboBoxContentLang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabelNumerator.setText("Тип нумерации");

        jComboBoxNumerator.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "LatinNumeration", "RussianNumeration ", "OtherNumeration " }));

        jLabel1.setText("Тип сортировки");

        jComboBoxSorting.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\"0\"/\"ordinary\"", "\"1\"/\"withoutDiacritics\"" }));

        jScrollPane1.setViewportView(jTextPaneStatus);

        jButtonExport.setText("Экпорт");

        jCheckBoxFormat.setSelected(true);
        jCheckBoxFormat.setText("Форматировать XML файл");

        jLabelTarget.setText("Куда сохранять");
        jLabelTarget.setToolTipText("");

        jButtonStop.setText("Стоп");

        jCheckBoxMergeHomonym.setText("Объединять омонимы");
        jCheckBoxMergeHomonym.setEnabled(false);

        jCheckBoxMergeHomograph.setText("Объединять омографы");
        jCheckBoxMergeHomograph.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelDictName)
                            .addComponent(jLabelIndexLang)
                            .addComponent(jLabelContentLang)
                            .addComponent(jLabelNumerator)
                            .addComponent(jLabel1)
                            .addComponent(jLabelTarget))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxNumerator, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextFieldDictName)
                                    .addComponent(jComboBoxContentLang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBoxIndexLang, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBoxSorting, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextFieldTarget))
                                .addContainerGap())
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBoxAddLabels)
                                    .addComponent(jCheckBoxMergeHomonym))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBoxMergeHomograph)
                                    .addComponent(jCheckBoxFormat))
                                .addGap(0, 84, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButtonStop)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonExport)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDictName)
                    .addComponent(jTextFieldDictName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelIndexLang)
                    .addComponent(jComboBoxIndexLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelContentLang)
                    .addComponent(jComboBoxContentLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxNumerator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNumerator))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxSorting, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBoxAddLabels)
                    .addComponent(jCheckBoxFormat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBoxMergeHomonym)
                    .addComponent(jCheckBoxMergeHomograph))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTarget, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTarget))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonExport)
                    .addComponent(jButtonStop))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonExport;
    private javax.swing.JButton jButtonStop;
    private javax.swing.JCheckBox jCheckBoxAddLabels;
    private javax.swing.JCheckBox jCheckBoxFormat;
    private javax.swing.JCheckBox jCheckBoxMergeHomograph;
    private javax.swing.JCheckBox jCheckBoxMergeHomonym;
    private javax.swing.JComboBox jComboBoxContentLang;
    private javax.swing.JComboBox jComboBoxIndexLang;
    private javax.swing.JComboBox jComboBoxNumerator;
    private javax.swing.JComboBox jComboBoxSorting;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelContentLang;
    private javax.swing.JLabel jLabelDictName;
    private javax.swing.JLabel jLabelIndexLang;
    private javax.swing.JLabel jLabelNumerator;
    private javax.swing.JLabel jLabelTarget;
    private javax.swing.JProgressBar jProgressBar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextFieldDictName;
    private javax.swing.JTextField jTextFieldTarget;
    private javax.swing.JTextPane jTextPaneStatus;
    // End of variables declaration//GEN-END:variables
}
